package com.quanyan.place.thread;

import com.quanyan.place.entity.*;
import com.quanyan.place.mapper.TbBizPlaceUnitSalePlanMainMapper;
import com.quanyan.place.mapper.TbBizPlaceUnitSalePlanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by youxiaojia on 2016/9/2.
 */
public class ModifyPlaceUnitNameThread implements Runnable {
    private Logger logger = LoggerFactory.getLogger(ModifyPlaceUnitNameThread.class);

    private TbBizPlaceUnitSalePlanMapper tbBizPlaceUnitSalePlanMapper;
    private TbBizPlaceUnitSalePlanMainMapper tbBizPlaceUnitSalePlanMainMapper;
    private String placeUnitName;
    private Integer placeUnitId;

    public ModifyPlaceUnitNameThread(TbBizPlaceUnitSalePlanMapper tbBizPlaceUnitSalePlanMapper, TbBizPlaceUnitSalePlanMainMapper tbBizPlaceUnitSalePlanMainMapper, String placeUnitName, Integer placeUnitId) {
        this.tbBizPlaceUnitSalePlanMapper = tbBizPlaceUnitSalePlanMapper;
        this.tbBizPlaceUnitSalePlanMainMapper = tbBizPlaceUnitSalePlanMainMapper;
        this.placeUnitName = placeUnitName;
        this.placeUnitId = placeUnitId;
    }

    @Override
    public void run() {
        try {
            logger.debug("————————————————————————更新销售计划，销售模板——————————————————————");
            TbBizPlaceUnitSalePlanExample example1 = new TbBizPlaceUnitSalePlanExample();
            TbBizPlaceUnitSalePlanExample.Criteria criteria1 = example1.createCriteria();
            criteria1.andPlaceUnitIdEqualTo(placeUnitId);
            TbBizPlaceUnitSalePlan updatePlaceUnitSalePlan = new TbBizPlaceUnitSalePlan();
            updatePlaceUnitSalePlan.setPlaceUnitName(placeUnitName);
            tbBizPlaceUnitSalePlanMapper.updateByExampleSelective(updatePlaceUnitSalePlan, example1);

            TbBizPlaceUnitSalePlanMainExample example2 = new TbBizPlaceUnitSalePlanMainExample();
            TbBizPlaceUnitSalePlanMainExample.Criteria criteria2 = example2.createCriteria();
            criteria2.andPlaceUnitIdEqualTo(placeUnitId);
            TbBizPlaceUnitSalePlanMain updatePlaceUnitSalePlanMain = new TbBizPlaceUnitSalePlanMain();
            updatePlaceUnitSalePlanMain.setPlaceUnitName(placeUnitName);
            tbBizPlaceUnitSalePlanMainMapper.updateByExampleSelective(updatePlaceUnitSalePlanMain, example2);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
}
